package top.loveyumin1314.music.cmd;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import top.loveyumin1314.music.bean.SessionBean;
import top.loveyumin1314.music.bean.UserActionBean;
import top.loveyumin1314.music.bean.UserListBean;
import top.loveyumin1314.music.code.ActionCode;
import top.loveyumin1314.music.util.JacksonUtil;

/**
 * author Kerry
 * date 2017/10/10
 * desp null
 */

public class CreateResponse {


    public static CreateResponse create() {
        return new CreateResponse();
    }

    private UserActionBean userActionBean;

    private CreateResponse() {
        userActionBean = new UserActionBean();
    }

    public CreateResponse setUserActionBeanWithActionCode(UserActionBean sessionBean, ActionCode ac) {
        sessionBean.setActionId(ac.actionId);
        sessionBean.setActionDetail(ac.actionDetail);
        sessionBean.setTime(System.currentTimeMillis());
        this.userActionBean = sessionBean;
        return this;
    }

    public CreateResponse setUserActionBean(UserActionBean userActionBean) {
        this.userActionBean = userActionBean;
        return this;
    }

    public CreateResponse setUserId(String userId) {
        userActionBean.setUserId(userId);
        return this;
    }

    public CreateResponse setUserName(String userName) {
        userActionBean.setUserName(userName);
        return this;
    }

    public CreateResponse setData(Object data) {
        userActionBean.setData(data);
        return this;
    }

    public CreateResponse setActionInfo(ActionCode ac) {
        userActionBean.setActionId(ac.actionId);
        userActionBean.setActionDetail(ac.actionDetail);
        return this;
    }


    public String build() throws JsonProcessingException {
        return JacksonUtil.actionBean2Data(userActionBean);
    }

    public TextWebSocketFrame buildWebSocketFrame() throws JsonProcessingException {
        return new TextWebSocketFrame(JacksonUtil.actionBean2Data(userActionBean));
    }

    public TextWebSocketFrame buildWebSocketFrame(Object obj) throws JsonProcessingException {
        return new TextWebSocketFrame(JacksonUtil.actionBean2Data(obj));
    }
}
